home *** CD-ROM | disk | FTP | other *** search
- Path: nova.umuc.edu!not-for-mail
- From: cm140c31@nova.umuc.edu (Robert Rodgers)
- Newsgroups: comp.lang.c++
- Subject: Is there an asynchronous cin.peek()?
- Date: 15 Mar 1996 11:02:05 -0500
- Organization: University of Maryland University College
- Message-ID: <4ic49t$ivb@nova.umuc.edu>
- NNTP-Posting-Host: nova.umuc.edu
-
- I'm writing a small utility that needs to decide at runtime whether to
- read re-directed input (e.g., x < data.txt) or read the same input from a
- data file. I need to to compile clean, using the standard, portable
- libraries.
-
- The problem I'm encountering is, I'm not used to using cin/cout, and I
- can't find a way to do an asychronous peek at the input stream. For example:
-
- char x;
- if(EOF != (x = cin.peek())){
- cout << "x is going to be '" << x << "'.\n";
- }
-
- The problem is that if you compile this and run it *without* redirected
- input, it pauses until it gets some (any) input. I don't want this -- I
- want to check of the stream is empty, and if it's empty, skip ahead to
- the file parser. cin.peek() doesn't return until something enters the
- stream.
-
- Any help would be appreciated.
-
-
-